package com.zhuxiang.dao.impl;

import com.zhuxiang.dao.UserloginlogDao;
import com.zhuxiang.entity.Userloginlog;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional
public class UserloginlogDaoImpl implements UserloginlogDao {
    @Autowired
    private SessionFactory sessionFactory;
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    @Override
    public void addLoginlog(Userloginlog loginlog) {
        sessionFactory.getCurrentSession().save(loginlog);
    }

    @Override
    public List<Userloginlog> selectAll(int userId) {
        String hql = "from Userloginlog where userId = ?";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setParameter(0,userId);
        return query.list();
    }
}
